﻿
@{
    ViewBag.Title = "SafeChart";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<section class="content-header">
    <h1>
        登陆日志
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i>主页</a></li>
        <li class="active">登陆日志</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <div class="box-header">
                    <div class="bs-example">
                        <ul class="nav nav-tabs">
                            <li role="presentation"><a href="@Url.Action("SafeList","Log")">日志信息</a></li>
                            <li role="presentation" class="active"><a href="#">日志分析</a></li>
                        </ul>
                    </div>
                    <div class="form-inline" style="margin-top:10px;">
                        <div class="form-group">
                            <label>是否核心功能</label>
                            <select name="selIsCoreFunction" id="selIsCoreFunction" class="form-control">
                                <option selected="selected" value="-1">全部</option>
                                <option value="1">是</option>
                                <option value="0">否</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>是否常规业务</label>
                            <select name="selIsConventional" id="selIsConventional" class="form-control">
                                <option selected="selected" value="-1">全部</option>
                                <option value="1">是</option>
                                <option value="0">否</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>创建时间</label>
                            <input type="text" class="form-control" style="width:100px;" maxlength="20" id="txtStartDate" autocomplete="off" value="@DateTime.Now.ToString("yyyy-MM-dd")" />
                        </div>
                        <div class="form-group">
                            <input type="text" class="form-control" style="width:100px;" name="txtEndDate" maxlength="20" id="txtEndDate" autocomplete="off" />
                        </div>
                        <div class="form-group">
                            <button type="button" class="btn btn-success btn-sm" id="btnSearch">查找</button>
                        </div>
                        <h3 class="box-title"></h3>
                    </div>
                </div>

                <div class="box-body">
                    <div id="divChart" style="width: 1000px; height: 400px; margin-left: auto; margin-right: auto;"></div>
                    <div class="no-data" style="display:none;" id="NoData"><div class="img-box"></div><div class="text">暂无数据</div></div>
                </div>

            </div>
        </div>
    </div>
</section>
@section scriptsBottom{
    <script src="@Url.Content("~/js/echarts.min.js")"></script>
    <script type="text/javascript">
        // 基于准备好的dom，初始化echarts实例
        var divChart = echarts.init(document.getElementById('divChart'));
        $(document).ready(function () {
            dataBind();
            $("#txtStartDate").datepicker({
                language: "zh-CN",
                autoclose: true,//选中之后自动隐藏日期选择框
                format: "yyyy-mm-dd"//日期格式，
            });
            $("#txtEndDate").datepicker({
                language: "zh-CN",
                autoclose: true,//选中之后自动隐藏日期选择框
                format: "yyyy-mm-dd"//日期格式，
            });

            $("#btnSearch").click(function () {
                dataBind();
            });


        });

        function dataBind() {

                var startdate = $("#txtStartDate").val();
                var enddate = $("#txtEndDate").val();
                var defaultDate = '@DateTime.Now.ToString("yyyy-MM-dd")';
                var msg = "开始日期不能大于结束日期";
                if (startdate == '') {
                    startdate = defaultDate;
                }
                if (enddate == '') {
                    enddate = defaultDate;
                    msg = "开始日期不能大于当前日期";
                }
                var start = new Date(startdate.replace("-", "/").replace("-", "/"));
                var end = new Date(enddate.replace("-", "/").replace("-", "/"));
                var dfDate = new Date(defaultDate.replace("-", "/").replace("-", "/"));
                if (start > dfDate) {
                    BMCW.alert(msg);
                    return false;
                }
                if (end < start) {
                    BMCW.alert(msg);
                    return false;
                }
                var url = "@Url.Action("GetSafeStatisicData", "Log")";
                divChart.showLoading();
                BMCW.ajax({
                    type: "GET",
                    dataType: "json",
                    url: url,
                    data: {
                        selCoreFunction: $("#selIsCoreFunction").val(),
                        selConventional: $("#selIsConventional").val(),
                        txtStartDate: $("#txtStartDate").val(),
                        txtEndDate: $("#txtEndDate").val()
                    },
                    success: function (data) {
                        if (data.status == 0 && data.data.length > 0) {
                            $("#divChart").show();
                            $('#NoData').hide();
                            var data = data.data;
                            var arrName = [];
                            var arrCount = [];
                            for (var i = 0; i < data.length; i++) {
                                arrName.push(data[i].ModuleName);
                                arrCount.push(data[i].OperateCount);
                            }
                            SetChart(arrName, arrCount);
                        } else {
                            $("#divChart").hide();
                            $('#NoData').show();
                        }
                        divChart.hideLoading();
                    },
                    error: function () {
                        divChart.hideLoading();
                    }
                });
            }

            function SetChart(arrName,arrCount) {
                // 指定图表的配置项和数据
                var option = {
                    title: {
                        text: ''
                    },
                    tooltip: {},
                    legend: {
                        data: ['操作数量']
                    },
                    toolbox: {
                        show: true,
                        feature: {
                            mark: { show: true },
                            magicType: { show: true, type: ['line', 'bar'] },
                            restore: { show: true },
                            saveAsImage: { show: true },
                        }
                    },
                    xAxis: {
                        data: arrName,
                        axisLabel: {
                            interval: 0,
                            rotate: 40
                        }
                    },
                    yAxis: {},
                    series: [{
                        name: '操作数量',
                        type: 'bar',
                        data: arrCount
                    }]
                };
                // 使用刚指定的配置项和数据显示图表。
                divChart.setOption(option);
            }

    </script>
}




